layui.config({
    base: config.base + 'layui-admin/'
}).extend({
    index: 'lib/index'
}).use(['index'], function () {
    const $ = layui.$;
    const admin = layui.admin;
    const form = layui.form;
    const layer = layui.layer;
    const fn = {
        //登陆
        login: function (field) {
            admin.req({
                url: config.base + 'admin/login.json'
                , contentType: "application/json;charset=UTF-8"
                , type: 'post'
                , data: JSON.stringify(field)
                , done: function (data) {
                    layui.data('lockScreen', {key: 'lockStatus', value: false});
                    location.href = config.base + 'views/admin/index.html';
                    layer.msg('登入成功', {offset: '15px', icon: 1, time: 1000, shade: 0.01});
                }
                , complete: function () {
                    fn.captcha();
                }
            });
        }
        , captcha: function () {
            $('#login-captcha').attr('src', config.base + 'views/admin/captcha.jpg?t=' + new Date().getTime());
        }
    };
    form.on('submit(login-submit)', function (obj) {
        fn.login(obj.field);
    });
    $('#login-captcha').on('click', function () {
        fn.captcha();
    });
});